package conf

import (
	"fmt"
	"github.com/spf13/viper"
)

type Config struct {
	MysqlConfig
	RedisConfig
}

type MysqlConfig struct {
	Host     string
	Port     int
	User     string
	Password string
	Database string
}

type RedisConfig struct {
	Host     string
	Password string
}

var AppConfig Config
var err error

func Init() {
	viper.SetConfigFile("./conf/config.yaml")
	err = viper.ReadInConfig()
	if err != nil {
		fmt.Println("配置文件读取失败")
		return
	} else {
		fmt.Println("配置文件读取成功")
	}
	err = viper.Unmarshal(&AppConfig)
	if err != nil {
		fmt.Println("配置文件解析失败")
		return
	} else {
		fmt.Println("配置文件解析成功")
	}
}
